import com.alibaba.fastjson.JSON;

import java.io.BufferedReader;
import java.io.FileReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static final String fileName = "2020-08-11";

    public static void main(String[] args) {
        try {
            long startTime = 1596680398000l;
            long endTime = 1596694798000l;


            FileReader fileReader = new FileReader("E:\\down_demo\\ReadTxt\\src\\" + fileName + ".log");
            BufferedReader bufferedReader = new BufferedReader(fileReader);
            List<String> strings = new ArrayList<>();
            String str = null;
            List<GPS> gpsList = new ArrayList<>();
            int i = 0;
            GPS gps = new GPS();
            while ((str = bufferedReader.readLine()) != null) {
                if (str.trim().length() > 2 && str.contains("原始数据:")) {
                    String tmp = "";
                    String time = getVal(str, "时间", " 纬度");
                    long t = Long.parseLong(time);
                    //if (t > startTime && t < endTime) {
                        String la = getVal(str, "纬度", " 经度");
                        String lo = getVal(str, "经度", " 速度");

                        gps.la = la;
                        gps.lo = lo;
                        gps.time = time;
                        gpsList.add(gps);
                        i++;
                        //System.out.println("第" + i);
                        System.out.println("[" + lo + "," + la + "],");
                        //Connect_MySQL.insert(JSON.toJSONString(gps), "");
                    //}
                    str = null;
                }
            }
            //Connect_MySQL.insert(JSON.toJSONString(gpsList), "");
            //Connect_MySQL.close();
            System.out.println("===执行完成");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private static String getVal(String str, String start, String end) {
        String tmp;
        int start1 = str.indexOf(start);
        int start2 = str.indexOf(end);
        tmp = str.substring(start1 + 2, start2);
        return tmp;
    }

}
